import requests
from bs4 import BeautifulSoup
import csv
def get_html(url):
    head={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"}
    try:
        r=requests.get(url=url,headers=head)
        r.encoding=r.apparent_encoding
        r.raise_for_status()
        return r.text
    except Exception as err:
        print(err)
def parser(html):
    soup=BeautifulSoup(html,'lxml')
    out_list=[]
    for row in soup.select("li[class='row-6'] h1"):
        out_list1=[row.text]
        out_list.append(out_list1)
    for c in soup.select("li[class='row-3'] h1"):
        out_list2=[c.text]
        out_list.append(out_list2)
    return out_list
def save_csv(path,content):
    with open(path,'w+',newline='',encoding='utf-8')as f:
        csv_write=csv.writer(f)
        csv_write.writerows(content)
if __name__ == '__main__':
    url='https://www.mxbc.com/product'
    wo=get_html(url)
    out_list=parser(wo)
    path='wangjianshuo.csv'
    save_csv(path,out_list)














